package cn.kgc.watch.web;

import cn.kgc.watch.entity.Order;
import cn.kgc.watch.entity.OrderDetail;
import cn.kgc.watch.entity.ResultInfo;
import cn.kgc.watch.service.OrderDetailService;
import cn.kgc.watch.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
//订单
@CrossOrigin
public class OrderController {
    @Resource
    private OrderService orderService;
    @Resource
    private OrderDetailService orderDetailService;
    @GetMapping("findOrderByUserId")
    public List<Order> findOrderByUserId(Integer userId){
        return this.orderService.findOrderByUserId(userId);
    }
    @PostMapping("orderGo")
    public Long orderGo(@RequestBody Order order){
        System.out.println("order.getOrderId() = " + order.getOrderId());
        for (OrderDetail orderDetail : order.getOrderDetailList()) {
            System.out.println("orderDetail.getCommoditySku().getTitle() = " + orderDetail.getCommoditySku().getTitle());
        }
        return this.orderService.orderGo(order);
    }
    //找用户底下的所有的订单
    @GetMapping("showUserOrder")
    public ResultInfo showUserOrder(Integer userId){
        return new ResultInfo(200,"成功",this.orderService.findUserOrder(userId));
    }
    //同过orderId去找订订单详情
    @GetMapping("/showUserOrderDetail")
    public ResultInfo showUserOrderDetail(Integer orderId){
        System.out.println("this.orderDetailService.findOrderDetail(orderId) = " + this.orderDetailService.findOrderDetail(orderId));
        return new ResultInfo(200,"成功",this.orderDetailService.findOrderDetail(orderId));
    }
    @PutMapping("updateOrderState")
    public ResultInfo updateOrderState(@RequestBody Order order){
        this.orderService.modifyOrderState(order);
        return new ResultInfo(200,"修改成功");
    }
    @PutMapping("updateOrderPay")
    public ResultInfo updateOrderPay(@RequestBody Order order){
        this.orderService.modifyOrderPay(order);
        return new ResultInfo(200,"成功");
    }
}
